import React, {Component} from 'react';
import {
    View,
    StyleSheet,
    Text,
    TextInput
} from 'react-native';
 import GitHubTrending from 'GitHubTrending'
import NavigationBar from './js/common/NavigationBar'

const URL="https://github.com/trending/";
export default class TrendingTest extends Component {
    constructor(props) {
        super(props);
        this.trending=new GitHubTrending();
        this.state = {
            result:'',
        };
    }
    onload() {
        let url=URL+this.text;
        this.trending.fetchTrending(url)
            .then(result=>{
                 this.setState({
                     //得到的是一个数组
                     result:JSON.stringify(result),
                 })
            })
            .catch(error=>{
                this.setState({
                    result:JSON.stringify(error),
                })
            })
    }

  
    render() {
        return (
            <View style={styles.container}>
               <NavigationBar
                   title='GithubTrending的使用'
                   style={{backgroundColor: '#6495ed'}}
               />
               <TextInput 
                   style={{borderWidth:1,height:40,margin:6}}
                   onChangeText={text=>this.text=text}   
                />
                <View style={{flexDirection:'row'}}>
                    <Text style={styles.tips}
                        onPress={()=>this.onload()}                                                                                                                                                                                                                                                                                                                                                                                               
                    >加载数据</Text>
                    <Text style={{flex:1}}>{this.state.result}</Text>
                </View>
                {/* <Toast ref={toast=>this.toast=toast}/> */}
            </View>    
        )
    }
}
const styles =StyleSheet.create({
    container: {
        flex:1,
    },
    tips:{
        fontSize: 29,
        margin:5
    }
})